//
//  ShouyiXQ.m
//  投融保
//
//  Created by 523 on 14-1-19.
//  Copyright (c) 2014年 木叶科技. All rights reserved.
//

#import "ShouyiXQ.h"
#import "ParameterYongjinDetail.h"
#import "MYWebService.h"
#import "ShouyiDetailPerson.h"

@interface ShouyiXQ ()

@end

@implementation ShouyiXQ
@synthesize detailService;

extern ParameterYongjinDetail *parYongjinDetail;
extern NSString *key;
extern NSString *appKey;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setValueOfDetail) name:@"getAsyData" object:nil];
    /*********请求数据*********/
    NSLog(@"%@",parYongjinDetail.tradeId);
//    NSString *strAppBrokerageDetail=@"service=appBrokerageDetail&tradeId=465&detailId=1472&investDetailId=1470";
    NSString *strAppBrokerageDetail=[NSString stringWithFormat:@"service=appBrokerageDetail&tradeId=%@&detailId=%@&investDetailId=%@",parYongjinDetail.tradeId,parYongjinDetail.detailId,parYongjinDetail.investDetailId];
    detailService=[MYWebService new];
    [detailService getDataAsynWithKey:key encryptedString:strAppBrokerageDetail appKey:appKey];

    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)btnReturnAction:(UIButton *)sender {
    [[NSNotificationCenter defaultCenter] removeObserver:self];
    [self dismissViewControllerAnimated:NO completion:nil];
//    [self dismissModalViewControllerAnimated:NO];
}

- (void)setValueOfDetail
{
    

    NSLog(@"%@",detailService.profileDataAsyn);
    
    ShouyiDetailPerson *detail= [ShouyiDetailPerson parseFromDict:[[detailService.profileDataAsyn objectForKey:@"result"] objectForKey:@"dataMap"]]
    ;
    //投资日期
    NSDateFormatter *dateFormatter=[NSDateFormatter new];
    dateFormatter.dateFormat=@"yyyy-MM-dd";
    
    NSString *strDate=[dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[detail.date longLongValue]/1000]];
    //成立日期，到期日期
    NSString *strStartDate;
    NSString *strEndDate;
    if (![detail.effectiveDateTime isEqual:[NSNull null]]) {
        strStartDate=[dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[detail.effectiveDateTime longLongValue]/1000]];
    }
    if (![detail.expireDateTime isEqual:[NSNull null]]) {
        strEndDate=[dateFormatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[detail.expireDateTime longLongValue]/1000]];
    }
    
    
    
    //期限判断
    NSString *strLimit;
    if ([detail.timeLimitUnit isEqualToString:@"W"]) {
        strLimit=[NSString stringWithFormat:@"%@月",detail.timeLimit];
    }else if([detail.timeLimitUnit isEqualToString:@"D"])
    {
        strLimit=[NSString stringWithFormat:@"%@日",detail.timeLimit];
    }else if([detail.timeLimitUnit isEqualToString:@"Y"])
    {
        strLimit=[NSString stringWithFormat:@"%@年",detail.timeLimit];
    }
    
    //收益率 浮点转百分比
    NSNumberFormatter *numFormatter=[NSNumberFormatter new];
    [numFormatter setNumberStyle:NSNumberFormatterPercentStyle];
    NSString *strShouyilv=[numFormatter stringFromNumber:detail.interestRate];
    
    
    // 页面付值
    self.lblInvestorName.text=detail.investorRealName;
    self.lblAmount.text=[NSString stringWithFormat:@"￥%@",detail.touziAmount];
    self.lblInvestDate.text=strDate;
    self.lblYongjin.text=[NSString stringWithFormat:@"￥%@",detail.amount];
    self.lblLoanName.text=detail.loanName;
    self.lblLoanAmount.text=[NSString stringWithFormat:@"￥%@",detail.loanAmount];
    self.lblShouyilv.text=strShouyilv;
//    self.lblDuifuType.text=detail.
    self.lblEffectiveDateTime.text=strStartDate;
    self.lblExpireDateTime.text=strEndDate;
    self.lblTimeLimit.text=strLimit;
    
    
    
}
#pragma mark-   -----------状态栏底色------
- (UIStatusBarStyle)preferredStatusBarStyle
{
    [self.view setBackgroundColor:[UIColor blackColor]];
    return UIStatusBarStyleLightContent;
}
- (BOOL)prefersStatusBarHidden
{
    return NO;
}
@end
